using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.ComponentModel;
using System.Data;
using MAF.Common;

namespace My.GenCode
{
	public class NameHelper
	{
        /// <summary>
        /// 构造方法
        /// </summary>
        /// <param name="entityName"></param>
        /// <param name="serviceName"></param>
        /// <param name="companyName"></param>
        public NameHelper(string entityName,string serviceName,string companyName)
        {
            EntityName = entityName;
            ServiceName = serviceName;
            CompanyName = companyName;
        }

        #region 基础属性

        //0 实体单数名
        private string _EntityName = string.Empty;
        public string EntityName
        {
            get { return _EntityName; }
            set { _EntityName = WordsConverter.ToPascalCase(WordConverter.Singularize(value)); }
        }

        //0 实体复数名
        public string EntitiesName
        {
            get { return WordConverter.Pluralize(this.EntityName); }
        }

        // 实体所属服务名
        private string _ServiceName = string.Empty;
        public string ServiceName
        {
            get { return _ServiceName; }
            set { _ServiceName = value; }
        }

        // 实体所属公司名
        private string _CompanyName = string.Empty;
        public string CompanyName
        {
            get { return _CompanyName; }
            set { _CompanyName = value; }
        }

        // 命名空间
        private string _NameSpace = null;
        public string NameSpace
        {
            get 
            { 
                if( null==_NameSpace )
                    _NameSpace = this.CompanyName + "." + this.ServiceName;
                return _NameSpace;
            }
        }
        #endregion

        #region 类，文件 属性
        /// <summary>
        /// 0 实体类名
        /// </summary>
        public string EntityClassName
        {
            get { return this.EntityName + "Info"; }
        }
        /// <summary>
        /// 0 实体类文件名
        /// </summary>
        public string EntityClassFileName
        {
            get { return this.EntityClassName + ".cs"; }
        }

        /// <summary>
        /// 1 接口名
        /// </summary>
        public string InterfaceName
        {
            get{ return "I" + this.EntityName; }
        }
        /// <summary>
        /// 1 接口类文件名
        /// </summary>
        public string InterfaceFileName
        {
            get { return this.InterfaceName + ".cs"; }
        }

        /// <summary>
        /// 2 服务类名
        /// </summary>
        public string ServiceClassName
        {
            get { return ServiceName + "Manager"; }
        }
        /// <summary>
        /// 2 服务类文件名
        /// </summary>
        public string ServiceClassFileName
        {
            get { return this.ServiceClassName + ".cs"; }
        }

        /// <summary>
        /// 3 安全类名
        /// </summary>
        public string SafeClassName
        {
            get { return this.EntityName + "Safe"; }
        }
        /// <summary>
        /// 3 安全类文件名
        /// </summary>
        public string SafeClassFileName
        {
            get { return this.SafeClassName + ".cs"; }
        }

        /// <summary>
        /// 4 Dao类名
        /// </summary>
        public string DaoClassName
        {
            get{ return this.EntityName + "Dao"; }
        }
        /// <summary>
        /// 4 Dao类文件名
        /// </summary>
        public string DaoClassFileName
        {
            get { return this.DaoClassName + ".cs"; }
        }

        /// <summary>
        /// 5 SqlMap文件名
        /// </summary>
        public string SqlMapFileName
        {
            get { return EntitiesName + ".xml"; }
        }

        /// <summary>
        /// 6 Hanlder类名
        /// </summary>
        public string HandlerClassName
        {
            get{ return this.EntityName + "Handler"; }
        }
        /// <summary>
        /// 6 Hanlder类文件名
        /// </summary>
        public string HandlerClassFileName
        {
            get { return this.HandlerClassName + ".cs"; }
        }

        /// <summary>
        /// 7 Ajax页面文件名
        /// </summary>
        public string AjaxPageFileName
        {
            get { return "Ajax.aspx"; }
        }

        /// <summary>
        /// 8 Create页面文件名
        /// </summary>
        public string CreatePageFileName
        {
            get
            {
                return "Create" + this.EntityName + ".aspx";
            }
        }
        /// <summary>
        /// 9 Read List页面文件名
        /// </summary>
        public string ReadListPageFileName
        {
            get
            {
                return this.EntitiesName + "List.aspx";
            }
        }
        /// <summary>
        /// a Read Detail 方法名
        /// </summary>
        public string ReadDetailMethodName
        {
            get
            {
                return "Read" + this.EntityName + "ByConditions";
            }
        }

        /// <summary>
        /// -1 数据库脚本文件名
        /// </summary>
        public string DbScriptFileName
        {
            get { return this.ServiceName + ".sql"; }
        }
        #endregion

        #region 方法属性

        // Create方法名
        public string CreateMethodName
        {
            get
            { 
                return "Create" + this.EntityName; 
            }
        }
        // Create方法签名,即 返回值+方法名+参数列表
        public string CreateMethodSign
        {
            get
            {
                return "object " + CreateMethodName + "(" + this.EntityClassName + " info )";
            }
        }


        // Update方法名
        public string UpdateMethodName
        {
            get
            {
                return "Update" + this.EntityName;
            }
        }
        // Update方法签名
        public string UpdateMethodSign
        {
            get
            {
                return "int " + UpdateMethodName + "(" + this.EntityClassName + " info )";
            }
        }

        // Delete 方法名,批量删除数据
        public string DeleteMethodName
        {
            get
            {
                return "Delete" + this.EntitiesName;
            }
        }
        // Delete 方法签名
        public string DeleteMethodSign
        {
            get
            {
                return "int " + DeleteMethodName + "(" + this.EntityClassName + " info )";
            }
        }


        // Read Detail 方法签名
        public string ReadDetailMethodSign
        {
            get
            {
                return this.EntityClassName + " " + ReadDetailMethodName + "(" + this.EntityClassName + " info )";
            }
        }
        // Read Detail页面文件名
        public string ReadDetailPageFileName
        {
            get
            {
                return this.EntityName + "Detail.aspx";
            }
        }

        // Read List 方法名
        public string ReadListMethodName
        {
            get
            {
                return "Read" + this.EntitiesName + "ByConditions";
            }
        }
        // Read List 方法签名
        public string ReadListMethodSign
        {
            get
            {
                return "IList<" + this.EntityClassName + "> " + ReadListMethodName + "(" + this.EntityClassName + " info, int pageSize, int currentPage )";
            }
        }


        // Read Count 方法名
        public string ReadCountMethodName
        {
            get
            {
                return "Read" + this.EntitiesName + "CountByConditions";
            }
        }
        // Read Count 方法签名
        public string ReadCountMethodSign
        {
            get
            {
                return "int " + ReadCountMethodName + "( " + this.EntityClassName + " info )";
            }
        }
        #endregion

    }
}    
 
